package com.sky.controller;

import com.sky.constant.MessageConstant;
import com.sky.dto.CompetitionApplicationDTO;
import com.sky.dto.common.PageRequest;
import com.sky.dto.common.QueryParams;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CompetitionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/competition")
@Slf4j
@Validated
public class CompetitionController {
    @Autowired
    private CompetitionService competitionService;
    /**
     * 增加竞赛信息
     */
    @PostMapping("/add")
    public Result<String> addCompetitionCategory(@RequestBody CompetitionApplicationDTO competitionDTO)  {
       // 保存竞赛信息
        competitionService.save(competitionDTO);
        return Result.success(MessageConstant.OK_MESSAGE);
    }
    /**获取竞赛信息
     *
     */
    @PostMapping("/getCompetitionInfo")
    public Result<CompetitionApplicationDTO> getCompetitionInfo(@RequestBody Map<String, String> map)  {
        CompetitionApplicationDTO competition = competitionService.getById(map.get("id"));
        return Result.success(competition,MessageConstant.OK_MESSAGE);
    }
    /**
     * 分页获取竞赛申请信息
     */
    @PostMapping("/pageQuery")
    public Result<PageResult> pageQuery(@RequestBody PageRequest<QueryParams> queryParams)  {
        PageResult pageResult = competitionService.pageQuery(queryParams);
        return Result.success(pageResult,MessageConstant.OK_MESSAGE);
    }
}